package thread.lock;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-25 19:38
 **/
public class DeadLock1 {
    public static void main(String[] args) {
        Object o1 = new Object();
        Object o2 = new Object();

        //
        Runnable run1 = new Runnable() {
            @Override
            public void run() {
                synchronized (o1) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o2) {
                        System.out.println("这是一个寂寞的天");
                    }
                }
            }
        };

        //
        Runnable run2 = new Runnable() {
            @Override
            public void run() {
                synchronized (o2) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o1) {
                        System.out.println("下着有些伤心的雨");
                    }
                }
            }
        };

        //
        new Thread(run1, "线程1").start();
        new Thread(run2, "线程2").start();
    }
}
